package view;


import java.util.ArrayList;
import mdes.slick.sui.Button;
import mdes.slick.sui.Container;
import mdes.slick.sui.Display;
import mdes.slick.sui.event.ActionEvent;
import mdes.slick.sui.event.ActionListener;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.BasicGameState;
import org.newdawn.slick.state.StateBasedGame;
import org.newdawn.slick.state.transition.FadeInTransition;
import org.newdawn.slick.state.transition.FadeOutTransition;

public class MisterJumpCreditsMenu extends BasicGameState implements ActionListener {

        private int stateID = -1;
        private Image creditsImage;
        private Display display = null;
        private Button[] buttons = null;
        private int buttonYLocations[] = {470,470};
        private int buttonXLocations[] = {70,200};
    	private boolean backBtnPressed = false;
    	private boolean exitBtnPressed = false;
        
        public MisterJumpCreditsMenu(int stateID) {
                this.stateID = stateID;
        }
        
        @Override
        public void init(GameContainer container, StateBasedGame game) throws SlickException {
                creditsImage = new Image("data/credits_background.png");
        	    display = new Display(container);
        	    buttons = new Button[2];
        	    ArrayList buttonNames = new ArrayList(); buttonNames.add(0, "Back"); buttonNames.add(1,"Exit");
        	    Container buttonContainer = new Container(); buttonContainer.setSize(320, 512); buttonContainer.setLocation(0, 0); buttonContainer.setOpaque(false); 
    	        
        	    for (int i = 0; i < buttons.length; i++) {
        	    	buttons[i] = new Button(buttonNames.get(i).toString());
        			buttons[i].setLocation(buttonXLocations[i],buttonYLocations[i]);
        			buttons[i].addActionListener(this);
        			buttons[i].setActionCommand(buttonNames.get(i).toString());
        			buttons[i].pack();
        			buttonContainer.add(buttons[i]);
        		}
        	        
        	    display.add(buttonContainer);	    
        }

        @Override
        public void render(GameContainer container, StateBasedGame game, Graphics g) throws SlickException {
                creditsImage.draw(0,0);
                display.render(container, g);
        }

        @Override
        public void update(GameContainer container, StateBasedGame game, int delta)  throws SlickException {
        	if (backBtnPressed) {
				game.enterState(MisterJumpMain.MAINMENUSTATE, new FadeOutTransition(), new FadeInTransition());
				backBtnPressed = false;
			}
        	else if (exitBtnPressed) {
				container.exit();
			}
        	display.update(container, delta);
        }

        @Override
        public int getID() { return stateID; }

		@Override
        public void actionPerformed(ActionEvent e) {
			if ("Back".equals(e.getActionCommand())) {
				backBtnPressed = true;
			}else if ("Exit".equals(e.getActionCommand())) {
				exitBtnPressed = true;
			}
		}
}
